package com.tjzx.dao;

import java.sql.Timestamp;
import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.tjzx.entity.EipDocInfo;

/**
 * A data access object (DAO) providing persistence and search support for
 * EipDocInfo entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.tjzx.entity.EipDocInfo
 * @author MyEclipse Persistence Tools
 */

public class EipDocInfoDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(EipDocInfoDAO.class);
	// property constants
	public static final String SUBJECT = "subject";
	public static final String DOC_NO = "docNo";
	public static final String VERSION = "version";
	public static final String PUBDATE = "pubdate";
	public static final String PUBLISHER = "publisher";
	public static final String TOPIC_WORDS = "topicWords";
	public static final String SAFE_LEVEL = "safeLevel";
	public static final String STATUS = "status";
	public static final String FLAG = "flag";
	public static final String DESCRIPTION = "description";
	public static final String REMARK = "remark";
	public static final String DOC_TEXT = "docText";
	public static final String DOC_TYPE = "docType";
	public static final String ISDEL = "isdel";
	public static final String WRITER = "writer";
	public static final String HITS = "hits";
	public static final String CENT = "cent";
	public static final String TYPE1 = "type1";
	public static final String TYPE2 = "type2";
	public static final String DOC_FROM = "docFrom";
	public static final String UE_ID = "ueId";
	public static final String MOD_NAME = "modName";

	protected void initDao() {
		// do nothing
	}

	public void save(EipDocInfo transientInstance) {
		log.debug("saving EipDocInfo instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(EipDocInfo persistentInstance) {
		log.debug("deleting EipDocInfo instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public EipDocInfo findById(java.lang.Long id) {
		log.debug("getting EipDocInfo instance with id: " + id);
		try {
			EipDocInfo instance = (EipDocInfo) getHibernateTemplate().get(
					"com.tjzx.entity.EipDocInfo", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(EipDocInfo instance) {
		log.debug("finding EipDocInfo instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding EipDocInfo instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from EipDocInfo as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findBySubject(Object subject) {
		return findByProperty(SUBJECT, subject);
	}

	public List findByDocNo(Object docNo) {
		return findByProperty(DOC_NO, docNo);
	}

	public List findByVersion(Object version) {
		return findByProperty(VERSION, version);
	}

	public List findByPubdate(Object pubdate) {
		return findByProperty(PUBDATE, pubdate);
	}

	public List findByPublisher(Object publisher) {
		return findByProperty(PUBLISHER, publisher);
	}

	public List findByTopicWords(Object topicWords) {
		return findByProperty(TOPIC_WORDS, topicWords);
	}

	public List findBySafeLevel(Object safeLevel) {
		return findByProperty(SAFE_LEVEL, safeLevel);
	}

	public List findByStatus(Object status) {
		return findByProperty(STATUS, status);
	}

	public List findByFlag(Object flag) {
		return findByProperty(FLAG, flag);
	}

	public List findByDescription(Object description) {
		return findByProperty(DESCRIPTION, description);
	}

	public List findByRemark(Object remark) {
		return findByProperty(REMARK, remark);
	}

	public List findByDocText(Object docText) {
		return findByProperty(DOC_TEXT, docText);
	}

	public List findByDocType(Object docType) {
		return findByProperty(DOC_TYPE, docType);
	}

	public List findByIsdel(Object isdel) {
		return findByProperty(ISDEL, isdel);
	}

	public List findByWriter(Object writer) {
		return findByProperty(WRITER, writer);
	}

	public List findByHits(Object hits) {
		return findByProperty(HITS, hits);
	}

	public List findByCent(Object cent) {
		return findByProperty(CENT, cent);
	}

	public List findByType1(Object type1) {
		return findByProperty(TYPE1, type1);
	}

	public List findByType2(Object type2) {
		return findByProperty(TYPE2, type2);
	}

	public List findByDocFrom(Object docFrom) {
		return findByProperty(DOC_FROM, docFrom);
	}

	public List findByUeId(Object ueId) {
		return findByProperty(UE_ID, ueId);
	}

	public List findByModName(Object modName) {
		return findByProperty(MOD_NAME, modName);
	}

	public List findAll() {
		log.debug("finding all EipDocInfo instances");
		try {
			String queryString = "from EipDocInfo";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public EipDocInfo merge(EipDocInfo detachedInstance) {
		log.debug("merging EipDocInfo instance");
		try {
			EipDocInfo result = (EipDocInfo) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(EipDocInfo instance) {
		log.debug("attaching dirty EipDocInfo instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(EipDocInfo instance) {
		log.debug("attaching clean EipDocInfo instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static EipDocInfoDAO getFromApplicationContext(ApplicationContext ctx) {
		return (EipDocInfoDAO) ctx.getBean("EipDocInfoDAO");
	}
}